function initPageRecommend()
{
	$("#header").html("<p id='btnBack' class='btnHeaderBack btnHeaderLeft'></p>친구추천");
	new Quickly('btnBack', function(e){
		$.mobile.changePage("../main_sns.html",{transition:'flip'});
	});
	new Quickly('updateRecommendFriend', function(e){
		updateRecommendFriendToServer( user.id, user.mainbaby_info.babyid );
	});

	recommendFriendToServer( user.id, user.mainbaby_info.babyid );
}

function initPageMessageBox()
{
	$("#header").html("<p id='btnBack' class='btnHeaderBack btnHeaderLeft'></p>쪽지함");
	$("#user_bg").css("background-image", "url(../../images/white_pat.png)");
	$("#user_bg").css("height",$(window).height()+100);
	new Quickly('btnBack', function(e){
		$.mobile.changePage("../main_profile.html",{transition:'flip'});
	});
	
	requestMessageBoxToServer( user.mainbaby_info.babyid );
}

function initPageMessage()
{
	$("#header").html("<p id='btnBack' class='btnHeaderBack btnHeaderLeft'></p>쪽지");
	new Quickly('btnBack', function(e){
		$.mobile.changePage("../main_sns.html",{transition:'flip'});
	});
	new Quickly('send_message', function(e){
		messageInfo.select = true;
		$.mobile.changePage("sendMessage.html",{transition:'slide'});
	})

	requestMessageToServer( user.mainbaby_info.babyid, messageInfo.babyId );
}

function initPageSendMessage()
{
	$("#header").html("<p id='btnHeaderBack' class='btnHeaderBack btnHeaderLeft'></p>쪽지보내기<p id='btnHeaderComplete' class='btnHeaderComplete btnHeaderRight'></p>");
	new Quickly('btnHeaderBack', function(e){
		$.mobile.changePage("../main_profile.html",{transition:'slide'});
	});
	new Quickly('btnHeaderComplete', function(e){
		messageInfo.select = false;
		sendMessageToServer( user.id, user.mainbaby_info.babyid, messageInfo.babyId, $("#sendMessageText").val() );
	});	
}

function initPageNews()
{
	$("#header").html("알림<p id='btnHeaderClose' class='btnHeaderClose btnHeaderRight'></p>");
	new Quickly('btnHeaderClose', function(e){
		$.mobile.changePage("../"+nowURL,{transition:'slide'});
	});
	requestNewsToServer( user.id );
}

function initPageReply()
{
	$("#header").html("<p id='btnHeaderBack' class='btnHeaderBack btnHeaderLeft'></p>댓글 달기<p id='btnHeaderComplete' class='btnHeaderComplete btnHeaderRight'></p>");
	new Quickly('btnHeaderBack', function(e){
		$.mobile.changePage("../main_sns.html",{transition:'slide'});
	});

	new Quickly('btnHeaderComplete', function(e){
		type = (postInfo.selectedPostId != -1)? 'babyroom' : 'sns';
		postId = (postInfo.selectedPostId != -1)? postInfo.selectedPostId : snsPostInfo.selectedPostId;
		postUserId = (postInfo.selectedPostUserId != -1)?postInfo.selectedPostUserId : snsPostInfo.selectedPostUserId;

		sendReplyToServer( user.id, postId, postUserId, $("#replyText").val(), type );
	})
}

//수정 완료
function refreshRecommendFriend( friendList ){
	start=0;
	$("#recommendList").html("");
	$.each( friendList, function(i, item){
		var temp = "<li id='recommendFriendList' class='recommendFriendList'>"
				+ "<div class='list_li'>"
				+ "<div id='list_frame_bg"+(start+i)+"' class='list_frame_bg'>"
				+ "<img id='list_gender"+(start+i)+"' class='list_gender' src='../../images/profile/gender_male.png'>"
				+ "<p id='list_nick"+(start+i)+"' class='list_nick'>"+item.nick+"</p>"
				+ "<p id='list_babybirthday"+(start+i)+"' class='list_babybirthday'>생일 "+item.birthday.substr(0,10)+"</p>"
				+ "<p id='list_babyfrombirth"+(start+i)+"' class='list_babyfrombirth'>태어난지 "+countDay(item.birthday)+"일 되는 날</p>"
				+ "<p id='list_resemble_bg"+(start+i)+"' class='list_resemble_bg'><p id='list_resemble_text"+(start+i)+"' class='list_resemble_text'>"+checkSimilarity(item.similarity)+"%"
				+ "<input id='list_friendid"+(start+i)+"' style='display:none !important;' value='"+item.babyid+"'></p>"
				+ "</div></div></li>";
		$("#recommendList").append(temp);
		$("#list_frame_bg"+(start+i)).css("background-image", "url('../../images/list/sum_middle_baby.png'), "+ urlProfilePhoto(item.babyid, item.pf_name,"medium"));		
		$("#list_gender"+(start+i)).attr("src",checkGender(2, item.gender));
	});
	
	$("#recommendList #recommendFriendList").click(function(){
		var idx = $(".recommendFriendList").index($(this));
		profileInfo.babyId = $("#list_friendid"+idx).val();

		$.mobile.changePage("../main_profile.html",{transition:'none'});
	})

	for (x in myScroll) 
		myScroll[x].refresh(); 	
}

// 수정 완료
function refreshNews( newsList )
{
	$("#news_list").html("");	
	$.each( newsList, function(i, item){
		var temp = "<li id='newsItem' class='newsItem'>"
				+ "<div class='list_li'>"
				+ "<div id='list_frame_bg"+i+"' class='list_frame_bg'>"
				+ "<img id='list_gender"+i+"' class='list_gender' src='../../images/profile/gender_male.png'>"
				+ "<p id='list_nick"+i+"' class='list_nick'>"+item.from_name+"</p>"
				+ "<p id='list_contents"+i+"' class='list_contents'>"+item.content+"</p>"
				+ "<input id='newsInfo"+i+"' class='newsInfo' style='display:none;' value='"+item.type+","+item.newsid+"'>"
				+ "</div></div></li>";
		
		$("#news_list").append(temp);

		// 프로필 사진 확인
		if( item.pf_name != null)
			$("#list_frame_bg"+i).css("background-image", urlMediumFrame(1, item.gender)+", "+ urlProfilePhoto(item.babyid, item.pf_name,"medium"));		

		// 성별 확인
		$("#list_gender"+i).attr("src",checkGender(2, item.gender));
	})
	// 리스트를 클릭하면 요청 수락
	$("#news_list #newsItem").click(function(){
		var idx = $(".newsItem").index($(this));
		acceptRequestNewsToServer( user.id, $("#newsInfo"+idx).val().substr(2,10), $("#newsInfo"+idx).val().substr(0,1) );	
	})	
}

/*수정 완료(보완-messageBox div click event)*/
function refreshMessageBox( d )
{
	$("#messageBoxList").html("");
	var temp="";
	$.each( d.message, function(i, item){
		if( i%2 == 0 )
			temp += "<li>";

		itemTime = new Date( dateTimeFormat ( item.datetime ) );
		temp += "<div id='messageBox_div"+i+"' class='messageBox_div'>"
				+ "<div id='messageBox_frame_bg"+i+"' class='messageBox_frame_bg'>"
				+ "<p id='messageBox_nick"+i+"' class='messageBox_nick'>"+item.name+"</p>"
				+ "<p id='messageBox_count"+i+"' class='messageBox_count'>"+item.numOfMessage+"</p></div>"
				+ "<p id='messageBox_contents"+i+"' class='messageBox_contents'>"+item.message+"</p>"
				+ "<p id='messageBox_time"+i+"' class='messageBox_time'>"+dynamicDate(itemTime/1000)+"</p>"
				+ "<input id='messageBox_fromBabyId"+i+"' style='display:none;' value='"+item.babyid+"'>"
				+ "</div>";

		if( i%2 == 1 )
			temp += "</li>";
	});

	if(d.total_msg_num%2 == 1)
		temp += "</li>";
		
	$("#messageBoxList").append(temp);
	
	$.each( d.message, function(i, item){
		$("#messageBox_frame_bg"+i).css("background-image", "url(../../images/mainframe/sum_small_baby.png), "+ urlProfilePhoto(item.babyid, item.pf_name,"small"));		

		$("#messageBox_div"+i).click(function(){
			btn = $(this);
			messageInfo.babyId = $("#messageBox_fromBabyId"+(btn.attr("id").substr(14,10) * 1) ).val();
			$.mobile.changePage("message.html", {transition:"slide"});
		});
	});
	
	for (x in myScroll) 
		myScroll[x].refresh(); 
}

/*수정 완료*/
function refreshMessage( d )
{
	$("#messageList").html("");
	$.each(d.message, function(i, item){
		
		itemTime = new Date( dateTimeFormat( item.datetime ) );
		var temp = "<li id='messageLi"+i+"'>"
				+ "<div id='messageDiv"+i+"' class='message_li'>"
				+ "<div id='message_frame_bg"+i+"' class='message_frame_bg'>"
				+ "<p id='message_nick"+i+"' class='message_nick'>"+item.name+"</p>"
				+ "<p id='message_time"+i+"' class='message_time'>"+dynamicDate(itemTime/1000)+"</p>"
				+ "<p id='message_contents"+i+"' class='message_contents'>"+item.message+"</p>"
				+ "</div></li>";
		
		$("#messageList").append(temp);
		// item.isFromMe를 가지고 보낸건지 받는건지 판단.

		$("#message_frame_bg"+i).css("background-image", urlProfileFrame(2, 1, item.gender)+", "+ urlProfilePhoto(item.babyid, item.pf_name,"small"));

		$('#messageLi'+i).css("height", (39+($("#message_contents"+i).css('height').replace('px','')*1))+"px" );
		$('#messageDiv'+i).css("height", (39+($("#message_contents"+i).css('height').replace('px','')*1))+"px" );
	})

	for (x in myScroll) 
		myScroll[x].refresh(); 
}